<!--  -->
<template>
    <section class="products-section1">
        <div class="container1">
            <!-- 筛选器 -->
            <div class="filter-container" v-if="showFilter">
                <div class="filter-dropdown">
                    <span class="filter-label">Filter</span>
                </div>
            </div>

            <!-- 页面标题 -->
            <h2 class="section-title" v-if="showCategory">{{ categoryDetail.name }}</h2>

            <!-- 产品网格 -->
            <div class="products-grid">
                <!-- 产品卡片1 -->
                <div class="product-card" v-for="(item, index) in productList" :key="index"
                    @click="handleViewProduct(item)">
                    <div class="product-image">
                        <img class="image-item" :src="item.productImage[0]" :alt="item.name" loading="lazy">
                    </div>
                    <div class="product-info">
                        <h3 class="product-title">{{ item.name }}</h3>
                        <p class="product-description">{{ item.subName }}</p>

                        <button class="view-product-btn">View Product</button>
                    </div>
                </div>
            </div>

            <div style="width: 100%;display: flex;justify-content: center;margin-top:30px" v-if="showLoadMore">
                <button class="load-more-btn" @click="handleLoadMore">Load More</button>
            </div>
        </div>
    </section>
</template>

<script>
export default {
    data() {
        return {

        };
    },
    props: {
        showCategory: {
            type: Boolean,
            default: false
        },
        categoryDetail: {
            type: Object,
            default: () => ({})
        },
        showLoadMore: {
            type: Boolean,
            default: false
        },
        productList: {
            type: Array,
            default: () => []
        },
        showFilter: {
            type: Boolean,
            default: true
        },
    },
    mounted() {

    },
    methods: {
        handleViewProduct(product) {
            this.$router.push({ name: "products", query: { productId: product ? product.id : "1" } });
        },
        handleLoadMore() {
            this.$emit("loadMoreProducts");
        },
    },
}
</script>
<style scoped>
/* 产品列表样式 */
/* .products-section {
    padding: 60px 20px;
    background-color: #ffffff;
}

.container {
    max-width: 1600px;
    margin: 0 auto;
} */

.filter-container {
    display: flex;
    justify-content: flex-start;
    margin-bottom: 20px;
}

.filter-dropdown {
    position: relative;
    display: inline-block;
}

.filter-label {
    padding: 8px 16px;
    background-color: #f5f5f5;
    border: 1px solid #e0e0e0;
    border-radius: 4px;
    cursor: pointer;
    font-size: 16px;
    font-weight: 700;
}

.filter-label:hover {
    background-color: #e8e8e8;
}

.section-title {
    font-size: 28px;
    font-weight: 700;
    margin-bottom: 40px;
    color: #333333;
}

.products-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 30px;
}

.product-card {
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    overflow: hidden;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    display: flex;
    flex-direction: column;
    background-color: #ffffff;
}

.product-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.1);
}

.product-image {
    /* padding: 20px; */
    text-align: center;
    background-color: #f9f9f9;
    min-height: 200px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.product-image img {
    max-width: 100%;
    height: 365px;
    object-fit: cover;
}

.product-info {
    padding: 20px;
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: space-around;
}

.product-title {
    font-size: 20px;
    font-weight: 700;
    margin-bottom: 15px;
    color: #0e0e0e;
    line-height: 1.4;
    text-align: center;
}

.product-description {
    text-align: center;
    font-size: 14px;
    color: #333333;
    margin-bottom: 25px;
    font-weight: 500;
}

.product-details {
    font-size: 13px;
    color: #333333;
    margin-bottom: 15px;
    line-height: 1.5;
    flex: 1;
    text-align: center;
}

.product-rating {
    display: flex;
    align-items: center;
    margin-bottom: 20px;
}

.rating-stars {
    color: #ffc107;
    font-size: 20px;
    margin-right: 8px;
    text-align: center;
    margin: 0 auto;
}

.rating-count {
    font-size: 14px;
    color: #333333;
    font-weight: 700;
}

.view-product-btn {
    background-color: #809e2c;
    color: white;
    border: none;
    font-weight: 700;
    font-size: 16px;
    padding: 15px 20px;
    border-radius: 34px;
    cursor: pointer;
    transition: background-color 0.3s ease;
    width: 100%;
}

.view-product-btn:hover {
    background-color: #6c8a26;
}

/* 响应式设计 */
@media (max-width: 1200px) {
    .products-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .image-item {
        width: 100%;
        height: 453px !important;
    }

    .product-title {
        font-size: 35px !important;
        margin-top: 0;
    }

    .product-info {
        max-width: 100% !important;
        padding: 15px;
    }

    .product-description {
        font-size: 30px !important;
        margin-top: 0;
    }

    .view-product-btn {
        font-size: 33px !important;
    }
}

@media (max-width: 768px) {
    .products-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 20px;
    }

    .section-title {
        font-size: 24px;
        margin-bottom: 30px;
    }

    .product-image {
        padding: 15px;
        min-height: 150px;
    }

    .product-info {
        max-width: 100% !important;
        padding: 15px;
    }

    .image-item {
        width: 100%;
        height: auto !important;
    }

    .product-title {
        font-size: 35px !important;
    }
}

@media (max-width: 480px) {
    .products-grid {
        grid-template-columns: 1fr;
    }

    .section-title {
        font-size: 20px;
        text-align: center;
    }
}

.load-more-btn {
    border: 1px solid #34773f;
    background-color: transparent;
    color: #34773f;
    border-radius: 50px;
    font-weight: 700;
    font-size: 18px;
    padding: 20px 20px;
    border-radius: 34px;
    cursor: pointer;
    transition: background-color 0.3s ease;
    width: 250px;
    margin: 30px auto;
}

.load-more-btn:hover {
    background-color: #34773f;
    color: white;
}
</style>
